package com.qx.dao;

import com.qx.pojo.Department;
import com.qx.pojo.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
@Repository
public class EmploryeeDao {
    public static Map<Integer,Employee> Employees=null;
    @Autowired
    private DepartmentDao departmentDao;

    static {
        Employees= new HashMap<>();
        Employees.put(1,new  Employee(1,"xmx",1,"xiaoming@11.com",new Department(1,"技术部")));
        Employees.put(2,new Employee(2, "lyr", 0, "1345xxx@qq.com", new Department(2, "财务部")));
        Employees.put(3,new  Employee(3,"jcl",0,"jcl@11.com",new Department(3, "市场部")));
        Employees.put(4,new Employee(4, "mcs", 1, "mcs@qq.com", new Department(5, "后勤部")));
    }
    private static Integer initialID=5;
//新增员工
    public void add(Employee employee){
        if (employee.getId()==null){
            employee.setId(initialID++);
        }
        employee.setDepartment(departmentDao.getDepartment(employee.getDepartment().getId()));
        Employees.put(employee.getId(),employee);
    }

    public Collection<Employee>getall(){
//        System.out.println(Employees.values());
        return Employees.values();
    }
    //通过ID查询员工
    public Employee getallbyid(Integer id){
        return Employees.get(id);
    }
    //删除员工
    public void del(Integer id){
        Employees.remove(id);
    }

}
